#include "LocalScene.h"
#include "Utils/LogUtil.h"
#include "Utils/StringUtil.h"
#include "Game/Component/Model.h"
#include "Render/RenderState.h"
#include "Render/Imgui/imgui.h"
#include "Math/Random.h"
#include "Game/GameState.h"
#include "LocalProcess.h"


void LocalScene::OnInit()
{
	mCamera.SetSpeed(8.f);

	mCoordinateProcess = GetProcess<CoordinateProcess>("CoordinateProcess");

	mLocalProcess = GetProcess<LocalProcess>("LocalProcess");

	mOctree = NewObject<Octree>(glm::vec3(-BOX_SIZE * 0.5f), glm::vec3(BOX_SIZE * 0.5f), 1);

	const int32 ballNum = 40;
	const float ballSpeed = 0.1f;
	const float ballRadius = 4.f;

	for (int32 i = 0; i < ballNum; ++i)
	{
		Ball* ball = NewObject<Ball>();
		ball->position = glm::vec3(Random64::Rand(-1.f, 1.f) * 4.f, Random64::Rand(-1.f, 1.f) * 4.f, Random64::Rand(-1.f, 1.f) * 4.f);
		ball->velocity = glm::vec3(Random64::Rand(-1.f, 1.f) * ballSpeed, Random64::Rand(-1.f, 1.f) * ballSpeed, Random64::Rand(-1.f, 1.f) * ballSpeed);
		ball->radius = Random64::Rand(0.1f, 0.2f) * ballRadius;
		ball->color = glm::vec3(Random64::Rand(0.f, 1.f), Random64::Rand(0.f, 1.f), Random64::Rand(0.f, 1.f));

		mBalls.push_back(ball);
		mOctree->Add(ball);
	}

	mTimeUntilUpdate = 0.f;
}

void LocalScene::OnTick(float deltaTime)
{
	Advance(mBalls, mOctree, deltaTime, mTimeUntilUpdate);
}

void LocalScene::OnImgui()
{
	if (ImGui::BeginMainMenuBar())
	{
		ImGui::Text("Fps : %d ", GRenderState->GetFps());

		ImGui::EndMainMenuBar();
	}


}

void LocalScene::OnExit()
{

}